﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExtAppBuilder.Ext.Configuration;

namespace ExtAppBuilder.Ext
{
    public class Component : Util.Observable
    {

        /// <summary>
        /// Initializes the component
        /// </summary>
        /// <param name="config">Configuration to be used while initializing</param>
        public Component(ComponentConfig config) : base(config)
        {            
            throw new NotImplementedException();
        }

        /// <summary>
        /// True if this component is disabled. Read-only.
        /// </summary>
        public bool Disabled { get; set; }

        /// <summary>
        /// The Ext.Element which encapsulates this Component. Read-only.This will usually be a DIV element 
        /// created by the class's onRender method, but that may be overridden using the autoEl config.
        /// </summary>
        public object El { get; set; }

        /// <summary>
        /// True if this component is hidden. Read-Only.
        /// </summary>
        public bool Hidden { get; set; }

        /// <summary>
        /// This Component's initial configuration specification. Read-only.
        /// </summary>
        public ComponentConfig InitialConfig { get; set; }

        /// <summary>
        /// The component's owner Ext.Container (defaults to undefined, and is set automatically when the 
        /// component is added to a container). Read-only.
        /// Note: to access items within the container see itemId.
        /// </summary>
        public object OwnerCt { get; set; }

        /// <summary>
        /// True if this component has been rendered. Read-only.
        /// </summary>
        public bool Rendered { get; set; }

        /// <summary>
        /// Fires after the component rendering is finished.
        /// The afterrender event is fired after this Component has been rendered, been postprocesed by any 
        /// afterRender method defined for the Component, and, if stateful, after state has been restored.
        /// </summary>
        public event AfterRenderHandler AfterRender;

        /// <summary>
        /// Handler used by the AfterRender event
        /// </summary>
        /// <param name="sender">Ext.Component</param>
        public delegate void AfterRenderHandler(Component sender);

        /// <summary>
        /// Fires before the component is destroyed. Return false from an event handler to stop the destroy.
        /// </summary>
        public event BeforeDestroyHandler BeforeDestroy;

        /// <summary>
        /// Handler used by the BeforeDestroyHandler event
        /// </summary>
        /// <param name="sender">Ext.Component</param>        
        public delegate void BeforeDestroyHandler(Component sender);

        /// <summary>
        /// Fires before the component is hidden by calling the hide method. Return false from an event handler to stop the hide.
        /// </summary>
        public event BeforeHideHandler BeforeHide;

        /// <summary>
        /// Handler used by the BeforeHide event
        /// </summary>
        /// <param name="sender">Ext.Component</param>
        public delegate void BeforeHideHandler(Component sender);

        /// <summary>
        /// Fires before the component is rendered. Return false from an event handler to stop the render.
        /// </summary>
        public event BeforeRenderHandler BeforeRender;

        /// <summary>
        /// Handler used by the BeforeRender event
        /// </summary>
        /// <param name="sender">Ext.Component</param>
        public delegate void BeforeRenderHandler(Component sender);

        /// <summary>
        /// Fires before the component is shown by calling the show method. Return false from an event handler 
        /// to stop the show.
        /// </summary>
        public event BeforeShowHandler BeforeShow;

        /// <summary>
        /// Handler used by the BeforeShow event
        /// </summary>
        /// <param name="sender">Ext.Component</param>
        public delegate void BeforeShowHandler(Component sender);

        /// <summary>
        /// Fires before the state of the component is restored. Return false from an event handler to stop 
        /// the restore.
        /// </summary>
        public event BeforeStateRestoreHandler BeforeStateRestore;

        /// <summary>
        /// Handler used by the BeforeStateRestore event
        /// </summary>
        /// <param name="sender">Ext.Component</param>
        /// <param name="state">The hash of state values returned from the StateProvider</param>
        public delegate void BeforeStateRestoreHandler(Component sender, object state);

        /// <summary>
        /// Fires before the state of the component is saved to the configured state provider. 
        /// Return false to stop the save.
        /// </summary>
        public event BeforeStateSaveHandler BeforeStateSave;

        /// <summary>
        /// Handler used by the BeforeStateSave event
        /// </summary>
        /// <param name="sender">Ext.Component</param>
        /// <param name="state">The of state values</param>
        public delegate void BeforeStateSaveHandler(Component sender, object state);

        /// <summary>
        /// Fires after the component is destroyed.
        /// </summary>
        public event DestroyHandler Destroy;

        /// <summary>
        /// Handler used by the Destroy event
        /// </summary>
        /// <param name="sender">Ext.Component</param>
        public delegate void DestroyHandler(Component sender);

        /// <summary>
        /// Fires after the component is disabled
        /// </summary>
        public event DisableHandler Disable;

        /// <summary>
        /// Handler used by the Disable event
        /// </summary>
        /// <param name="sender">Ext.Component</param>
        public delegate void DisableHandler(Component sender);

        /// <summary>
        /// Fires after the component is enabled.
        /// </summary>
        public event EnableHandler Enable;

        /// <summary>
        /// Handler used by the Enable event
        /// </summary>
        /// <param name="sender">Ext.Component</param>
        public delegate void EnableHandler(Component sender);

        /// <summary>
        /// Fires after the component is hidden when calling the hide method.
        /// </summary>
        public event HideHandler Hide;

        /// <summary>
        /// Handler used by the Hide event
        /// </summary>
        /// <param name="sender">Ext.Component</param>
        public delegate void HideHandler(Component sender);

        /// <summary>
        /// Fires after the component markup is rendered
        /// </summary>
        public event RenderHandler Render;

        /// <summary>
        /// Handler used by the Render event
        /// </summary>
        /// <param name="sender">Ext.Component</param>
        public delegate void RenderHandler(Component sender);

        /// <summary>
        /// Fires after the component is shown when calling the show method.
        /// </summary>
        public event ShowHandler Show;

        /// <summary>
        /// Handler used by the Show event
        /// </summary>
        /// <param name="sender">Ext.Component</param>
        public delegate void ShowHandler(Component sender);

        /// <summary>
        /// Fires after the state of the component is restored.
        /// </summary>
        public event StateRestoreHandler StateRestore;

        /// <summary>
        /// Handler used by the StateRestore event
        /// </summary>
        /// <param name="sender">Ext.Component</param>
        /// <param name="state">The hash of state values returned from the StateProvider</param>
        public delegate void StateRestoreHandler(Component sender, object state);

        /// <summary>
        /// Fires after the state of the component is saved to the configured state provider.
        /// </summary>
        public event StateSaveHandler StateSave;

        /// <summary>
        /// Handler used by the StateSave event
        /// </summary>
        /// <param name="sender">Ext.Component</param>
        /// <param name="state">The hash of state values returned from the StateProvider</param>
        public delegate void StateSaveHandler(Component sender, object state);
    }
}
